package cmd

import (
	"caas-platform-payment/internal/controller/channel"
	"caas-platform-payment/internal/controller/wechat"
	"context"

	"gitee.com/liangziyisheng/caas-platform-mc/utility/authentication"
	"gitee.com/liangziyisheng/caas-platform-mc/utility/authorization"

	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/gf/v2/os/gcmd"
)

var (
	Main = gcmd.Command{
		Name:  "platform-payment",
		Usage: "支付服务",
		Brief: "start http server",
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			s := g.Server()
			s.Group("/api", func(group *ghttp.RouterGroup) {
				group.POST("/payment/wxpay/paynotify/{tenantCode}/{appId}", new(wechat.ExtControllerV1).PayNotify)
				group.POST("/payment/wxpay/refundnotify/{tenantCode}/{appId}", new(wechat.ExtControllerV1).RefundNotify)
				group.Group("/payment", func(gpf *ghttp.RouterGroup) {
					gpf.Middleware(ghttp.MiddlewareCORS)
					gpf.Middleware(authentication.ValidToken)
					gpf.Middleware(authorization.CasbinMiddleware)
					gpf.Middleware(ghttp.MiddlewareHandlerResponse)
					gpf.Group("/", func(gps *ghttp.RouterGroup) {
						gps.Bind(
							channel.NewV1(),
						)
					})
					gpf.Group("/wxpay", func(gps *ghttp.RouterGroup) {
						gps.Bind(wechat.NewV1())
					})

				})

			})
			s.Run()
			return nil
		},
	}
)
